<template>
  <div>
    <h3>{{message.title}}</h3>
    <div class="message-head">
      <span>时间：{{message.add_time | dataFormat}}</span>
      <span>点击：{{message.click}}</span>
    </div>
    <hr />
    <!-- 缩略图区域 -->
    <div class="thumbs">
      <vue-preview :slides="list" class="preview preview-img"></vue-preview>
    </div>

    <div class="content" v-html="message.content"></div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      id: this.$route.params.id,
      message: {},
      list: []
    };
  },
  methods: {
    createdInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(result => {
        if (result.body.status == 0) {
          this.message = result.body.message[0];
        }
      });
    },
    getThumbs() {
      // 获取缩略图
      this.$http.get("api/getthumimages/" + this.id).then(result => {
        if (result.body.status === 0) {
          // 循环每个图片数据，补全图片的宽和高
          result.body.message.forEach(item => {
            item.msrc = item.src;
            item.w = 600;
            item.h = 400;
          });
          // 把完整的数据保存到 list 中
          this.list = result.body.message;
          console.log(this.list);
        }
      });
    },
    setPreview: function() {
      //给预览图设置参数
      return this.list;
    }
  },
  created() {
    this.createdInfo();
    this.getThumbs();
  }
};
</script>

<style scoped>
.message-head {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
}
.preview-img {
  margin: 10px;
  box-shadow: 0 0 8px #999;
}
.thumbs {
  display: flex;
  flex-wrap: wrap;
}
.content{
  font-size: 13px;
  line-height: 30px;
}
</style>